/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelInterfazEthernetRouter.java
 *
 * Created on 01/02/2012, 11:07:01
 */

package tsb.UI.Paneles.ROUTER;

import tsb.dominio.enumeraciones.AsignacionIP;
import tsb.dominio.interfaces.Ethernet;
import tsb.dominio.interfaces.IP;

/**
 *
 * @author Nico
 */
public class PanelEthernetRouter extends javax.swing.JPanel {

    /** Creates new form PanelInterfazEthernetRouter */
    public PanelEthernetRouter() {
        initComponents();
    }

      /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        chkAnchoBanda = new javax.swing.JCheckBox();
        rbtn10 = new javax.swing.JRadioButton();
        rbtn100 = new javax.swing.JRadioButton();
        rbtn1000 = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        txtIP = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtMascara = new javax.swing.JTextField();
        cmbEstado = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        rbDuplex = new javax.swing.JRadioButton();
        rbFullDuplex = new javax.swing.JRadioButton();
        chkAutoDuplex = new javax.swing.JCheckBox();

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Ancho de Banda"));
        jPanel1.setAlignmentX(0.3F);
        jPanel1.setAlignmentY(0.3F);

        chkAnchoBanda.setBackground(new java.awt.Color(255, 255, 255));
        chkAnchoBanda.setFont(new java.awt.Font("Tahoma", 0, 14));
        chkAnchoBanda.setSelected(true);
        chkAnchoBanda.setText("Auto");
        chkAnchoBanda.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                chkAnchoBandaMouseClicked(evt);
            }
        });

        rbtn10.setBackground(new java.awt.Color(255, 255, 255));
        rbtn10.setFont(new java.awt.Font("Tahoma", 0, 14));
        rbtn10.setText("10");
        rbtn10.setEnabled(false);

        rbtn100.setBackground(new java.awt.Color(255, 255, 255));
        rbtn100.setFont(new java.awt.Font("Tahoma", 0, 14));
        rbtn100.setText("100");
        rbtn100.setEnabled(false);

        rbtn1000.setBackground(new java.awt.Color(255, 255, 255));
        rbtn1000.setFont(new java.awt.Font("Tahoma", 0, 14));
        rbtn1000.setSelected(true);
        rbtn1000.setText("1000");
        rbtn1000.setEnabled(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(rbtn10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbtn100)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(rbtn1000))
                    .addComponent(chkAnchoBanda))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(chkAnchoBanda)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rbtn10)
                    .addComponent(rbtn100)
                    .addComponent(rbtn1000)))
        );

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Configuración IP"));
        jPanel2.setAlignmentX(0.0F);
        jPanel2.setAlignmentY(0.0F);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel3.setText("IP");

        txtIP.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel4.setText("Mascara");

        txtMascara.setHorizontalAlignment(javax.swing.JTextField.RIGHT);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(41, 41, 41)
                        .addComponent(txtIP, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtMascara, javax.swing.GroupLayout.DEFAULT_SIZE, 295, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtMascara, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(23, 23, 23))
        );

        cmbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "      Si ", "      No" }));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel1.setText("Encendido:");

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Duplex"));

        rbDuplex.setBackground(new java.awt.Color(255, 255, 255));
        rbDuplex.setText("Duplex");
        rbDuplex.setEnabled(false);

        rbFullDuplex.setBackground(new java.awt.Color(255, 255, 255));
        rbFullDuplex.setSelected(true);
        rbFullDuplex.setText("Full Duplex");
        rbFullDuplex.setEnabled(false);

        chkAutoDuplex.setBackground(new java.awt.Color(255, 255, 255));
        chkAutoDuplex.setSelected(true);
        chkAutoDuplex.setText("Auto");
        chkAutoDuplex.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                chkAutoDuplexMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(chkAutoDuplex)
                .addGap(18, 18, 18)
                .addComponent(rbDuplex)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(rbFullDuplex)
                .addContainerGap(44, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(chkAutoDuplex)
                    .addComponent(rbDuplex)
                    .addComponent(rbFullDuplex))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(cmbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void chkAnchoBandaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chkAnchoBandaMouseClicked

        if(this.chkAnchoBanda.isSelected()) {
            this.rbtn10.setEnabled(false);
            this.rbtn100.setEnabled(false);
            this.rbtn1000.setEnabled(false);
        } else {
            this.rbtn10.setEnabled(true);
            this.rbtn100.setEnabled(true);
            this.rbtn1000.setEnabled(true);
        }
}//GEN-LAST:event_chkAnchoBandaMouseClicked

    private void chkAutoDuplexMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_chkAutoDuplexMouseClicked

        if(this.chkAutoDuplex.isSelected()) {
            this.rbDuplex.setEnabled(false);
            this.rbFullDuplex.setEnabled(false);
        } else {
            this.rbDuplex.setEnabled(true);
            this.rbFullDuplex.setEnabled(true);
        }
}//GEN-LAST:event_chkAutoDuplexMouseClicked
public boolean estado()
    {
        if(this.cmbEstado.getSelectedIndex()==0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }



    public int getAnchoDeBanda()
    {
        if(this.rbtn10.isSelected())
        {
            return 10;
        }
        if(this.rbtn100.isSelected())
        {
            return 100;
        }

        return 1000;

    }
      public IP getIP()
    {
        IP ip=null;

            String cad=this.txtIP.getText();
            if(IP.comprobrarIP(cad))
            {
                    ip = new IP(cad);
            }
            else
            {return null;}

        return ip;
    }

    public IP getMascara()
    {
        try
        {
            IP ip = new IP(this.txtMascara.getText());
            return ip;
        }
        catch(Exception e)
        {}
        return null;
   }
    public boolean getAutoDuplex()
    {
        if(this.chkAutoDuplex.isSelected())
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    public boolean getDuplex()
    {
        if(this.rbDuplex.isSelected())
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public boolean getAnchoAuto()
    {
        if(this.chkAnchoBanda.isSelected())
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public Ethernet getEthernet()
    {
        boolean estado= estado();
        int anchoBanda= getAnchoDeBanda();

        IP IP= getIP();

        IP mascara= getMascara();

        boolean duplex;
        if(this.rbDuplex.isSelected())
        {duplex=true;}
        else
        {duplex=false;}

        boolean auto;
        if(getAnchoAuto())
        {auto=true;}
        else
        {auto=false;}



        Ethernet et = new Ethernet(estado, anchoBanda, IP, mascara, duplex, auto, null);

        return et;

    }
  
    
  

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox chkAnchoBanda;
    private javax.swing.JCheckBox chkAutoDuplex;
    private javax.swing.JComboBox cmbEstado;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JRadioButton rbDuplex;
    private javax.swing.JRadioButton rbFullDuplex;
    private javax.swing.JRadioButton rbtn10;
    private javax.swing.JRadioButton rbtn100;
    private javax.swing.JRadioButton rbtn1000;
    private javax.swing.JTextField txtIP;
    private javax.swing.JTextField txtMascara;
    // End of variables declaration//GEN-END:variables

}
